﻿using System;
using System.Configuration;
using System.Net.Configuration;
using System.Net.Mail;

namespace EXAM
{
    public class Sendmail
    {
        public static String FormAddress
        {
            get
            {
                SmtpSection cfg = (SmtpSection)ConfigurationManager.GetSection
                    ("system.net/mailSettings/smtp");
                return cfg.Network.UserName;
            }
        }

        public bool SendMail(string subject, string body,
        string to, bool isHtml, bool isSSL)
        {
            try
            {
                using (MailMessage mail = new MailMessage())
                {
                    mail.From = new MailAddress(FormAddress, "Vietnam Property Lease");
                    mail.To.Add(to);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = isHtml;
                    SmtpClient client = new SmtpClient();
                    client.EnableSsl = isSSL;
                    client.Send(mail);
                }
            }
            catch (SmtpException ex)
            {
                return false;
            }
            return true;
        }
    }



}
